package cn.shengchao.examstart.medialibrary.ohs.remote.rpc;

import cn.shengchao.examstar.rpc.product.api.IVideoHandle;
import cn.shengchao.examstart.medialibrary.acl.ports.repositories.IFileRepository;
import cn.shengchao.examstart.medialibrary.infrastructure.dao.po.TFile;
import cn.shengchao.examstart.medialibrary.ohs.local.appservice.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Slf4j
@DubboService
public class VideoHandle implements IVideoHandle {

    @Autowired
    IFileRepository iFileRepository;

    @Autowired
    private VideoService videoService;

    @Override
    public void handleVideoTask() {
        List<TFile> tFileTasks = iFileRepository.getAllTackNotBrieflyIsNull();
        for (TFile file : tFileTasks) {
            try {
                if (file != null) {
                    log.info("开始处理视频任务,fileName:{},fileUrl:{}", file.getName(), file.getUrl());
                    videoService.getTaskResult(file.getUrl());
                }
            } catch (Exception e) {
                log.error("处理视频任务失败,fileName:{},fileUrl:{}", file.getName(), file.getUrl(), e);
            }
        }
    }
}
